<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="shortcut icon" href="img/logo.ico" type="image/x-icon">
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo.jpeg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer1"></span>
        <a href="login.html">登录</a>
        <a href="reg.html">注册</a>
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登录框 -->
        <div class="login-dialog">
            <h3 id="login">登录</h3>
            <div class="row">
                <input type="text" placeholder="用户名" id="username">
            </div>
            <div class="row">
                <input type="password" placeholder="密码" id="password">
            </div>
            <div class="row">
                <button id="submit" onclick="mySubmit()">登录</button>
            </div>
        </div>
    </div>
    <script>
        jQuery(document).keyup(function(event) {
            if (event.keyCode == 13) {
                jQuery("#submit").click();
            }
        });

        function mySubmit() {
            var username = jQuery("#username");
            var password = jQuery("#password");
            // 非空校验
            if (jQuery.trim(username.val()) == "") {
                alert("请输入用户名！");
                username.focus();
                return;
            }
            if (jQuery.trim(password.val()) == "") {
                alert("请输入密码！");
                password.focus();
                return;
            }
            // 请求后端接口
            jQuery.ajax({
                url: "login",
                type: "POST",
                data: {
                    "username": username.val(),
                    "password": password.val()
                },
                success: function(data) {
                    if (data.data != null) {
                        if (data.data == true) {
                            location.href = "myblog_list.html";
                        } else {
                            alert("用户名或密码错误");
                        }
                    } else {
                        alert("服务器繁忙！");
                    }
                }
            });
        }
    </script>
</body>

</html>